package com.beiwei.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beiwei.auto.mode.Department;
import com.beiwei.mapper.VDepartmentMapper;
import com.beiwei.mode.VDepartment;

@Service
public class DepartmentService {

	@Autowired
	private VDepartmentMapper vDepartmentMapper;

	/**
	 * 根据公司的id查询该公司所有的部门（联动查询。按需加载）
	 */
	public List<VDepartment> findVDepartmentListByCompanyId(Integer companyId) throws Exception {

		return vDepartmentMapper.findVDepartmentListByCompanyId(companyId);
	}

	/**
	 * 根据部门id查询该部门信息
	 */
	public Department findDepartmentByDepartmentId(Integer departmentId) throws Exception {

		return vDepartmentMapper.selectByPrimaryKey(departmentId);
	}

	/**
	 * 修改保存部门
	 */
	public boolean saveDepartment(Department department) throws Exception {
		if (1 == vDepartmentMapper.updateByPrimaryKeySelective(department)) {
			return true;
		}

		return false;
	}

	/**
	 * 新加保存部门
	 */
	public boolean addDepartment(Department department) throws Exception {
		if (1 == vDepartmentMapper.insertSelective(department)) {
			return true;
		}
		return false;
	}

}
